// 导入数据库操作模块
const { mysql } = require("../../db");

// 获取状态正常的路由
exports.Menu = async (req, res) => {
	try {
		let sqlStr;
		if (req.user.roles === "SuperAdmin") {
			sqlStr = "SELECT * FROM routes";
		} else {
			sqlStr = "SELECT * FROM routes WHERE is_show = 0 AND permission = ?";
		}
        
		const [results] = await mysql.query(sqlStr);
		if (results.length === 0) return res.error("暂无路由!");
		res.success(results);
	} catch (err) {
		res.error(err);
	}
};